﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZP.Common;
using ZP.DTO.Common;
using ZP.DTO.fz_sys_role;
using ZP.IBLL;

namespace ZCSBZPJ.Controllers
{
    public class FZRoleController : BaseController
    {
        //public FZRoleController(Ifz_sys_roleService _fz_sys_roleService)
        //{
        //    this._fz_sys_roleService = _fz_sys_roleService;
        //}

        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 获得所有角色信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public JsonResult GetAllSysRole()
        {
            PageModel<fz_sys_roleResultDTO> pageList = new PageModel<fz_sys_roleResultDTO>();
            try
            {
                pageList = _fz_sys_roleService.GetSysRole(null, false);
            }
            catch (Exception ex)
            {
                pageList.msg = ex.Message;
            }
            return Json(pageList);
        }

        /// <summary>
        /// 角色信息-分页模糊查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public JsonResult GetSysRole(fz_sys_roleSearchDTO dto)
        {
            PageModel<fz_sys_roleResultDTO> pageList = new PageModel<fz_sys_roleResultDTO>();
            try
            {
                pageList = _fz_sys_roleService.GetSysRole(dto);
            }
            catch (Exception ex)
            {
                pageList.msg = ex.Message;
            }
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增和修改-保存角色信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public JsonResult SaveSysRole(fz_sys_roleOperateDTO dto)
        {
            ResultData<string> result = new ResultData<string>();
            try
            {
                result.SubmitResult = _fz_sys_roleService.SaveSysRole(dto);
            }
            catch (Exception e)
            {
                result.SubmitResult = false;
                result.Message = e.Message;
            }

            return Json(result);
        }

        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public JsonResult DeleteSysRole(List<fz_sys_roleOperateDTO> dto)
        {
            ResultData<string> result = new ResultData<string>();
            try
            {
                UserLoginDTO loginUser = (UserLoginDTO)Session[ZPCommon.SESSION_Login];
                result.SubmitResult = _fz_sys_roleService.DeleteSysRole(dto, loginUser);
            }
            catch (Exception ex)
            {
                result.SubmitResult = false;
                result.Message = ex.Message;
            }
            return Json(result);

        }

    }
}